# -*- coding: utf-8 -*-
"""
__title__ = ''
__author__ = 'Yang'
__mtime__ = '2018/12/22 17:31'
# code is far away from bugs with the god animal protecting
    I love animals. They taste delicious.
              ┏┓      ┏┓
            ┏┛┻━━━┛┻┓
            ┃      ☃      ┃
            ┃  ┳┛  ┗┳  ┃
            ┃      ┻      ┃
            ┗━┓      ┏━┛
                ┃      ┗━━━┓
                ┃  神兽保佑    ┣┓
                ┃　永无BUG！   ┏┛
                ┗┓┓┏━┳┓┏┛
                  ┃┫┫  ┃┫┫
                  ┗┻┛  ┗┻┛
"""
import numpy as np
import pandas as pd
import pymysql
import time
import re
import requests
from bs4 import BeautifulSoup
import json


def get_soup(url):
    page = requests.get(url.format(0)).text
    page = BeautifulSoup(page, 'lxml')
    return page


res = {}
for i in range(1, 3):
    url = 'http://www.boohee.com/food/group/{0}'
    url = url.format(i)
    d = {}
    for j in range(1, 11):
        url_ = url + '?page={0}'
        time.sleep(1)
        url_ = url_.format(j)
        soup = get_soup(url_)
        s = soup.select('.item')
        for k in s:
            txt = k.select('p')[0].text.replace('热量：', '')
            d[k.select('a')[1].text] = {'热量：': txt}
    title = soup.select('.widget-food-list')[0].select('h3')[0].text
    res[title] = [d]
print(res)
fp = open('test.txt', 'w')
json.dump(res, fp, ensure_ascii=False)
